import gugga.application.ApplicatiotionNavigationalStateMemento;
import gugga.common.ICommand;
import gugga.commands.INavigationCommandReceiver;

/**
 * @author Krasimir
 */
class gugga.commands.NavigationCommand 
	implements ICommand 
{
	private var mReceiver:INavigationCommandReceiver;
	private var mPreviousState:ApplicatiotionNavigationalStateMemento;
	private var mNavigateTo:String;
	
	public function NavigationCommand(aNavigateTo:String)
	{
		mReceiver = INavigationCommandReceiver(_global.ApplicationController);
		mNavigateTo = aNavigateTo;
	}

	public function execute() : Boolean 
	{
		mPreviousState =  mReceiver.createNavigationState();
		return mReceiver.navigateTo(mNavigateTo);
	}

	public function isReversible() : Boolean 
	{
		return true;
	}

	public function undo() : Void 
	{
	 	mReceiver.setNavigationState(mPreviousState);
	}
	
	public function clone():ICommand
	{
		var  copy:NavigationCommand =  new NavigationCommand(this.mNavigateTo);
		
		copy.mNavigateTo = this.mNavigateTo;
		copy.mPreviousState = this.mPreviousState;
//		copy.mApplication = this.mApplication;
		copy.mReceiver = this.mReceiver;
		return copy; 
	}
}